﻿namespace CatUtils.Utils.SpecialUtils.DataTool.Mysql
{/// <summary>
/// 数据库演示文件
/// </summary>
    public class MysqlDemo
    {
        private static readonly string DatabaseName = "pixiv";

        /// <summary>
        /// 初始化信息
        /// </summary>
        public void InitSql()
        {
            new MysqlTool().Select(DatabaseName);
            new MysqlTool().CreateTable(DatabaseName, string.Format(
           "CREATE TABLE `{0}`.`sainbed` ( `id` INT  AUTO_INCREMENT , `pixivname` VARCHAR(255) NOT NULL , `filename` VARCHAR(255) NOT NULL , PRIMARY KEY (`id`)) ENGINE = MyISAM;",

          DatabaseName));
        }

        /// <summary>
        /// 插入基础数据
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="Saincode"></param>
        /// <returns></returns>
        public int InsertData(string FileName, string Saincode)
        {
            return new MysqlTool().Insert(string.Format(
                "INSERT INTO `sainbed` (`id`, `pixivname`, `saincode`) VALUES (NULL, '{0}', '{1}');", FileName, Saincode
                ), DatabaseName);
        }

        /// <summary>
        /// 判断某个值是否存在
        /// </summary>
        /// <param name="Column"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool ValueExits(string Column, string Value)
        {
            return new MysqlTool().DataExits(DatabaseName, string.Format("SELECT * FROM `{0}` WHERE `pixivname` LIKE '{1}' ;", Column, Value));
        }
    }
}